﻿@{
    ViewData["Title"] = "Home Page";
}
<link href="~/lib/bootstrap/dist/css/bootstrap.css" rel="stylesheet" />
<h1>👨‍🚒很晚了，下播了，晚安各位</h1>
<div class="row">
    <div class="col-md-3">
        <div class="container ">
            <div id="myAlert" class="alert alert-info">
                <a href="#" class="close" data-dismiss="alert">&times;</a>
                <strong>MESSAGE BOX</strong>
            </div>
            <div class="row">
                <div class="col-md-5">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h3 class="panel-title"><a href="#">聊天板</a> </h3>
                        </div>
                        <div class="panel-body">
                            <div class="pre-scrollable">
                                <ul id="messagesList" style="height:340px"></ul>
                            </div>

                        </div>
                        <div class="panel-footer">
                            <input type="text" id="userName" placeholder="用户名" />
                            <input type="text" id="message" name="message" value="" placeholder="在此输入需要发送的消息" />
                            <button class="btn btn-info navbar-btn" type="button" id="sendBtn">发送</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>


    </div>
    <div class="col-md-3">
        <h2>How to</h2>
        <ul>
            <li><a href="https://go.microsoft.com/fwlink/?LinkID=398600">Add a Controller and View</a></li>
            <li><a href="https://go.microsoft.com/fwlink/?LinkId=699315">Manage User Secrets using Secret Manager.</a></li>
            <li><a href="https://go.microsoft.com/fwlink/?LinkId=699316">Use logging to log a message.</a></li>
            <li><a href="https://go.microsoft.com/fwlink/?LinkId=699317">Add packages using NuGet.</a></li>
            <li><a href="https://go.microsoft.com/fwlink/?LinkId=699319">Target development, staging or production environment.</a></li>
        </ul>
    </div>
    <div class="col-md-3">
        <h2>Overview</h2>
        <ul>
            <li><a href="https://go.microsoft.com/fwlink/?LinkId=518008">Conceptual overview of what is ASP.NET Core</a></li>
            <li><a href="https://go.microsoft.com/fwlink/?LinkId=699320">Fundamentals of ASP.NET Core such as Startup and middleware.</a></li>
            <li><a href="https://go.microsoft.com/fwlink/?LinkId=398602">Working with Data</a></li>
            <li><a href="https://go.microsoft.com/fwlink/?LinkId=398603">Security</a></li>
            <li><a href="https://go.microsoft.com/fwlink/?LinkID=699321">Client side development</a></li>
            <li><a href="https://go.microsoft.com/fwlink/?LinkID=699322">Develop on different platforms</a></li>
            <li><a href="https://go.microsoft.com/fwlink/?LinkID=699323">Read more on the documentation site</a></li>
        </ul>
    </div>
    <div class="col-md-3">
        <h2>Run &amp; Deploy</h2>
        <ul>
            <li><a href="https://go.microsoft.com/fwlink/?LinkID=517851">Run your app</a></li>
            <li><a href="https://go.microsoft.com/fwlink/?LinkID=517853">Run tools such as EF migrations and more</a></li>
            <li><a href="https://go.microsoft.com/fwlink/?LinkID=398609">Publish to Microsoft Azure Web Apps</a></li>
        </ul>
    </div>
</div>
<script src="~/lib/signalr/dist/browser/signalr.js"></script>
<script type="text/javascript">
    const connection = new signalR.HubConnectionBuilder()
        .withUrl("/myChatHub")
        .configureLogging(signalR.LogLevel.Information)
        .build();
    connection.start().catch(err => console.error(err.toString()));
    //定义方法使用connection.on方法来接收返回数据
    connection.on("SendMessage", (user, type) => {
        switch (type) {
            case 1:
                var a = document.createElement('a');
                //设置div的属性
                a.innerHTML = '<p>【解冻请求】来自患者ID：' + user + '点击处理</p>'; //设置显示的数据，可以是标签．
                a.class = "aui-btn aui-btn-info aui-btn-block aui-btn-outlined"
                a.href = "/admin/freezeoff?id=" + user
                var bo = document.getElementById("messagesList");//获取body对象.
                //动态插入到body中
                bo.insertBefore(a, bo.lastChild);
                break;
            case 2:
                var a = document.createElement('a');
                //设置div的属性
                a.innerHTML = '<p>【排班更变请求】来自医生ID：' + user + '点击处理</p>'; //设置显示的数据，可以是标签．
                a.class = "aui-btn aui-btn-info aui-btn-block aui-btn-outlined"
                a.href = "/admin/freezeoff?id=" + user
                var bo = document.getElementById("messagesList");//获取body对象.
                //动态插入到body中
                bo.insertBefore(a, bo.lastChild);
                break;
            default:
                break;
        }
      
    });

    document.getElementById("sendBtn").addEventListener("click", function () {
        var user = document.getElementById('userName').value;
        //从客户端中调用在此调用之前在自定义Hub定义的SendMessage方法
        connection.invoke("SendMessage", user,1).catch(err => console.error(err.toString()));
    });</script>